import { useLayoutStore } from "../../plugins/store";
import { computed, watch } from "vue";
import { useRouter } from "../../plugins/router/router";

/**
 * 当前选择的页面 Tab 改变后的处理事件
 */
export function useCurrentTabChange() {
  const layoutStore = useLayoutStore();
  const { route, toName } = useRouter();

  const current = computed<string>(() => {
    return layoutStore.current;
  });

  watch(current, function () {
    if (route.name !== current.value) {
      toName(current.value);
    }
  });
}
